package com.nulldev.util.networking.npacket4.extensions;

public class PacketExtensions {
	public static interface PacketExtensionID {
		/**
		 * Test extensions, is useless. <br>
		 * Known as: TST (Test Extension -> DEBUGGING)
		 */
		public static final int EXT_TEST = -1;
		/**
		 * Uses compression on packet. <br>
		 * TODO: Decompress data. <br>
		 * Known as: CMP (Packet Compression -> PROTOCOL)
		 */
		public static final int EXT_COMPRESSION = 1;
		/**
		 * Packet data is encrypted. <br>
		 * TODO: Implement P2PS a.k.a nPCrypt from nP 3.0 (Peer 2 Peer: Secure) <br>
		 * Known as: SEC (Secure Communications -> SECURITY)
		 */
		public static final int EXT_ENCRYPTED = 2;
		/**
		 * Segmented data. <br>
		 * NOTE: This packet is unused by the rUDP API as it is able to split packets.
		 * <br>
		 * Known as: XPD (Extended Packet Data -> PROTOCOL)
		 */
		public static final int EXT_PARTIAL_DATA = 3;
		/**
		 * Used by multicast mode in servers. <br>
		 * Known as: PPT (Packet Passthrough -> PROTOCOL)
		 */
		public static final int EXT_PASSED_THROUGH = 4;
		/**
		 * Used for port forwarding. <br>
		 * Known as: NPF (Automatic Port Forwarding -> PROTOCOL)
		 */
		public static final int EXT_PORT_FORWARDED = 5;
		/**
		 * Packets that are encrypted additionally and are undecipherable after key
		 * change. <br>
		 * Known as: OTP (One Time Packets -> SECURITY)
		 */
		public static final int EXT_ONE_TIME_PACKET = 6;
		/**
		 * Packet verification in the form of various encodings. <br>
		 * Known as: PHV (Packet Hash Verification -> SECURITY)
		 */
		public static final int EXT_PACKET_VERIFY = 8;
		/**
		 * Packet prioritization <br>
		 * Known as: PRI (Packet Priority -> PROTOCOL)
		 */
		public static final int EXT_PACKET_PRIORITY = 9;
		/*
		 * Blank the packet and its content. Used for spoofing data transfer. Known as:
		 * BLK (Packet Blanking -> Security)
		 */
		public static final int EXT_PACKET_BLANK = 10;
		/*
		 * Uses an identifier to keep a packet chain/topic. Used for sending multiple
		 * packets to a specific set of data. Known a: PKC (Packet Chaining -> Packet)
		 */
		public static final int EXT_PACKET_CHAIN = 11;

		/*
		 * Extension IDs: 15-20 have been reserved for MUX, these may be freed at a
		 * future date.
		 */

		// MST
		public static final int EXT_MUX_PACKET_STREAM_TYPE = 15;
		// MSC
		public static final int EXT_MUX_PACKET_STREAM_CONTROL = 16;
		// MSS
		public static final int EXT_MUX_PACKET_STREAM_SEGMENT = 17;
	}

	public static String getExtensionReadable(final int ext) {
		switch (ext) {
			case PacketExtensionID.EXT_COMPRESSION:
				return "CMP";
			case PacketExtensionID.EXT_ENCRYPTED:
				return "SEC";
			case PacketExtensionID.EXT_PACKET_VERIFY:
				return "PHV";
			case PacketExtensionID.EXT_PARTIAL_DATA:
				return "XPD";
			case PacketExtensionID.EXT_PASSED_THROUGH:
				return "PPT";
			case PacketExtensionID.EXT_TEST:
				return "TST";
			case PacketExtensionID.EXT_PORT_FORWARDED:
				return "NPD";
			case PacketExtensionID.EXT_ONE_TIME_PACKET:
				return "OTP";
			case PacketExtensionID.EXT_PACKET_PRIORITY:
				return "PRI";
			case PacketExtensionID.EXT_PACKET_CHAIN:
				return "PKC";
			case PacketExtensionID.EXT_MUX_PACKET_STREAM_TYPE:
				return "MST";
			case PacketExtensionID.EXT_MUX_PACKET_STREAM_CONTROL:
				return "MSC";
			case PacketExtensionID.EXT_MUX_PACKET_STREAM_SEGMENT:
				return "MSS";
			case PacketExtensionID.EXT_PACKET_BLANK:
				return "BLK";
			default:
				return "N/A";
		}
	}

	public static String[] getExtensionsReadable(final int... exts) {
		String[] out = new String[exts.length];
		for (int i = 0; i < exts.length; i++) {
			final int ext = exts[i];
			out[i] = getExtensionReadable(ext);
		}
		return out;
	}
}
